package rng

import (
	"github.com/shopspring/decimal"
	"math"
)

func BytesToFloat(arr []byte) float64 {
	number := decimal.NewFromFloat(0.0)
	l := len(arr)
	for i := 0; i < l; i++ {
		//value := float64(arr[i]) / math.Pow(256, float64(i+1))
		//number = number + value
		value := decimal.NewFromInt32(int32(arr[i])).Div(decimal.NewFromFloat(math.Pow(256, float64(i+1))))
		number = number.Add(value)
	}
	ret, _ := number.Float64()

	return ret
}

func ChunkArray(arr [64]byte, chunkSize, limit int) [][]byte {
	var groups [][]byte
	c := 0
	l := len(arr)
	skip := 0
	for i := 0; ; i = i + chunkSize {
		if i >= l || i+chunkSize > l {
			skip++
			i = skip
		}
		value := arr[i : i+chunkSize]
		groups = append(groups, value)
		c++
		if c >= limit {
			break
		}
	}

	return groups
}
